package com.example.hanfu_backend.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.hanfu_backend.entity.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Mapper
public interface GoodsMapper extends BaseMapper<Goods> {
    @Select("SELECT h.hanfu_name,h.hanfu_image,o.order_sum,o.order_address,o.order_size,o.order_price FROM goods o JOIN hanfu h ON o.hanfu_id = h.hanfu_id WHERE o.customer_id = #{customerId}")
    List<Map<String,Object>> getOneOrder(@RequestParam("customerId")Integer customerId);

    @Select("SELECT h.hanfu_name,h.hanfu_image,o.order_id,o.customer_id,o.order_sum,o.order_address,o.order_size,o.order_price FROM goods o JOIN hanfu h ON o.hanfu_id = h.hanfu_id" + "${ew.customSqlSegment}")
    List<Map<String,Object>> getAllOrder(Page<Map<String,Object>> page, @Param(Constants.WRAPPER)QueryWrapper<Map<String,Object>> queryWrapper);

    @Select("SELECT h.hanfu_name,h.hanfu_image,o.order_id,o.customer_id,o.order_sum,o.order_address,o.order_size,o.order_price FROM goods o JOIN hanfu h ON o.hanfu_id = h.hanfu_id")
    List<Map<String,Object>> getAllOrderNoPage();

    @Select("SELECT h.hanfu_name,SUM(g.order_sum) AS total_orders FROM goods g JOIN hanfu h ON g.hanfu_id = h.hanfu_id GROUP BY g.hanfu_id ORDER BY total_orders DESC LIMIT 10")
    List<Map<String,Object>> getTopTen();
}
